package client.gui;

import java.awt.Toolkit;
import java.util.*;

import javax.swing.*;

import sharedspace.*;
/**
 * this class show table of potential cheaters in test
 * its show to the teacher every combination of two student in test
 * and the amount of similar mistakes (only amount of 3 and more)
 * @author Amir S.
 * @author Jacob C.
 * @author Maya G.
 * @author Michael V.
 *
 */
public class GUI_CheatersTable extends JFrame {

	/**
	 * creates a table of Potential cheaters in the exam
	 * @param  List<Cheaters>
	 */
	private static final long serialVersionUID = 1L;
	private List<Cheaters> cList;
	private JTable cheatersTable;
	private JScrollPane cheatersScroller;
	private Toolkit toolkit = Toolkit.getDefaultToolkit();
	
	public GUI_CheatersTable(List<Cheaters> cList)
	{
		super();
		this.cList = cList;
		initialize();
		
	}
	
	public void initialize()
	{
		/*Initialize the frame*/
		this.setSize(600, 800);
		this.setLocation((toolkit.getScreenSize().width-600)/2, (toolkit.getScreenSize().height-800)/2);
		this.setTitle("Cheaters Table");
		this.setLayout(null);
		this.add(getCheatersTable());
	}
	/**
	 * 
	 * @return Table of cheaters
	 */
	public JScrollPane getCheatersTable()
	{
		String columnNames[] = {"Execute Test ID","Student1 ID","Student1 Name","Student2 ID","Student2 Name","Same Mistakes"};
		String[][] tableModel = new String[cList.size()][6];
		
		for(int i = 0; i<cList.size(); i++)
		{
			tableModel[i][0] = cList.get(i).getExecuteTest().getExecuteTestID();
			tableModel[i][1] = cList.get(i).getStudent1().getUserID();
			tableModel[i][2] = cList.get(i).getStudent1().getUserFirstName()+" "+cList.get(i).getStudent1().getUserLastName();
			tableModel[i][3] = cList.get(i).getStudent2().getUserID();
			tableModel[i][4] = cList.get(i).getStudent2().getUserFirstName()+" "+cList.get(i).getStudent2().getUserLastName();
			tableModel[i][5] = Integer.toString(cList.get(i).getSameMistake());
		}
		
		cheatersTable = new JTable(tableModel, columnNames){
			   /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int rowIndex, int colIndex) {
			   return false; //Disallow the editing of any cell
			   }
			   };
		cheatersTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		cheatersTable.getTableHeader().setReorderingAllowed(false);
		cheatersScroller = new JScrollPane(cheatersTable);
		cheatersScroller.setBounds(0, 0, 600, 800);
		
		
		return cheatersScroller;
	}

}
